package com.fanxl.security.core.authentication;

import com.fanxl.security.core.properties.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

/**
 * @description
 * @author: fanxl
 * @date: 2018/12/11 0011 18:06
 */
@Component
public class FormAuthenticationConfig {

    @Autowired
    private AuthenticationSuccessHandler fanAuthenticationSuccessHandler;

    @Autowired
    private AuthenticationFailureHandler fanAuthenctiationFailureHandler;

    public void configure(HttpSecurity http) throws Exception {
        http.formLogin()
                .loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)
                .loginProcessingUrl(SecurityConstants.DEFAULT_SIGN_IN_PROCESSING_URL_FORM)
                .successHandler(fanAuthenticationSuccessHandler)
                .failureHandler(fanAuthenctiationFailureHandler);
    }
}
